Socket
Socket
Sign inDemoInstall

meanie-mongoose-to-json

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

meanie-mongoose-to-json

A simple plugin for Mongoose to normalize JSON output for use with Meanie Express Seed projects


Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

meanie-mongoose-to-json

npm version node dependencies github issues codacy

A simple plugin for Mongoose to normalize JSON output, for use with Meanie Express Seed projects

Meanie

Installation

You can install this package using npm.

npm install meanie-mongoose-to-json --save

Usage

As a global plugin for all Mongoose schema's:

const mongoose = require('mongoose');
mongoose.plugin(require('meanie-mongoose-to-json'));

NOTE: as of Mongoose 4.5.4 this does not work for sub schema's yet, see #4271.

For a specific (sub) schema:

const mongoose = require('mongoose');
const Schema = mongoose.Schema;
const MySchema = new Schema({});
MySchema.plugin(require('meanie-mongoose-to-json'));

This plugin will normalize JSON output for client side applications from:

{
  "_id": "400e8324a71d4410b9dc3980b5f8cdea",
  "__v": 2,
  "name": "Item A"
}

To a simpler:

{
  "id": "400e8324a71d4410b9dc3980b5f8cdea",
  "name": "Item A"
}

From version 1.1.0 onwards, this plugin now also removes private paths from the JSON, e.g.:

const mongoose = require('mongoose');
const toJson = require('meanie-mongoose-to-json');

const schema = new mongoose.Schema({
  email: {type: String},
  password: {type: String, private: true},
});

schema.plugin(toJson);

const User = mongoose.model('users', schema);
const user = new User({email: 'test@test.com', password: 'test'});

console.log(user.toJSON());

This will output:

{
  "id": "400e8324a71d4410b9dc3980b5f8cdea",
  "email": "test@test.com"
}

Issues & feature requests

Please report any bugs, issues, suggestions and feature requests in the meanie-mongoose-to-json issue tracker.

Contributing

Pull requests are welcome! If you would like to contribute to Meanie, please check out the Meanie contributing guidelines.

Credits

  • Meanie logo designed by Quan-Lin Sim

License

(MIT License)

Copyright 2016-2017, Adam Reis

Keywords

FAQs

Package last updated on 22 Aug 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc